package com.event;

import com.mysqld.Mysqld;
import com.window.ChangeOwnPass;
import com.window.LoginStart;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;


public class ChangeOwnEvent implements ActionListener {
    public static String changepass;//记录修改的密码
    @Override
    public void actionPerformed(ActionEvent e) {

        char[] str = ChangeOwnPass.passwordtext.getPassword();
        String password = new String(str);
        char[] str1 = LoginStart.passwordtext.getPassword();
        String password1= new String(str1);
        this.changepass=password;
        if (changepass.equals("")) {
            JOptionPane.showMessageDialog(null, "密码不能为空", "修改密码", JOptionPane.WARNING_MESSAGE);
        } else if(changepass.equals(password1))
        {
            JOptionPane.showMessageDialog(null, "新旧密码相同!", "修改密码", JOptionPane.WARNING_MESSAGE);
        }
        else {
            try {
                Mysqld.changeownpass();
                JOptionPane.showMessageDialog(null, "更改成功!", "修改密码", JOptionPane.WARNING_MESSAGE);
                //修改成功后，关闭管理界面，打开登录界面
                ManageEvent.changeownPass.dispose();//关闭修改密码界面
                LoginEvent.manage.dispose();//关闭管理界面
                Mysqld.setStatus(0);//设置状态为0
                LoginStart a=new LoginStart();//打开登录界面
            } catch (Exception e1) {
            }
        }
    }
}
